package com.yupi.springbootinit.controller;

import com.yupi.springbootinit.common.BaseResponse;
import com.yupi.springbootinit.common.ResultUtils;
import com.yupi.springbootinit.model.dto.chart.GenChartByAiRequest;
import com.yupi.springbootinit.model.dto.test.WXtestRequest;
import com.yupi.springbootinit.model.entity.Chart;
import com.yupi.springbootinit.model.vo.BiResponse;
import com.yupi.springbootinit.service.ChartService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author xingyu Xue
 * @Date 2023/10/29 18:55
 */


@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Resource
    private ChartService chartService;


    private static final Long id =1727598807654068225l;

    @PostMapping("/getdata1")
    public BaseResponse<BiResponse> genChartByAi(GenChartByAiRequest genChartByAiRequest, HttpServletRequest request) {

        log.info("/test/getdata接口达到~~~~~");
        Chart resultChart = chartService.getById(id);
        String chartData = resultChart.getGenChart();
        String genResult = resultChart.getGenResult();
        Long id = resultChart.getId();




        BiResponse biResponse = new BiResponse();
        biResponse.setGenChart(chartData);
        biResponse.setGenResult(genResult);
        biResponse.setChartId(id);
        return ResultUtils.success(biResponse);


    }




    @GetMapping("/testWxNoBody")
    public String testWxNoBodyGet(HttpServletRequest httpServletRequest) {
        log.info("无参数接口到达~~~");
        String wXtest = httpServletRequest.getParameter("WXtest");
        log.info(wXtest);

        log.info("微信测试接口成功~~~");


        return "微信小程序测试接口成功~~~~";
    }

    @ApiOperation("测试小程序接口，post请求带参数")
    @PostMapping("/testWxWithBody")//@RequestBody WXtestRequest wXtestRequest,
    public String testWxWithBodyPost(@RequestBody WXtestRequest wXtestRequest,HttpServletRequest httpServletRequest) {
        log.info("有参数接口到达~~~testWxWithBodyPost~~~");
        log.info("spring boot hot deplay");
        String userAccount = wXtestRequest.getUserAccount();
        log.info(userAccount);
        String userPassword = wXtestRequest.getUserPassword();
        log.info(userPassword);
        String wxtest = wXtestRequest.getWxtestString();
        log.info(wxtest);
        log.info("微信测试接口成功~~~");
        return "微信小程序测试接口成功~~~~";
    }




    @GetMapping("/testWxWithBody")
    public String testWxWithBodyGet(@RequestBody WXtestRequest wXtestRequest, HttpServletRequest httpServletRequest) {
        log.info("有参数接口到达~~~");

        if (wXtestRequest == null) {
            log.info("无参数~~~");
        }


        log.info("微信测试接口成功~~~");



        return "微信小程序测试接口成功~~~~";
    }
}
